﻿@model Amazon_Book_Search.Models.SearchPage 
@{
    ViewBag.Title = "Search";
}

<div id="content">
    @using (Html.BeginForm("Search", "Search", FormMethod.Get)) {   
         <p> Title: @Html.TextBox("q") 
         <input type="submit" value="Search" /></p>
        }

    @if (Model.Items.Count != 0)
    {
    <table>
        <tr>
            <th>Pilt</th>
            <th>Kirjeldus</th>
            <th>Hind</th>
        </tr>
        @foreach (var item in Model.Items)
        {
            <tr>
                <td>
                @if (item.Image != null)
                {
                    <img src="@item.Image.URL" alt="pilt" />
                }
                </td>     
                <td>
                @if (item.Review != null)
                {
                    foreach (var x in item.Review)
                    {
                        <p>@item.Review.Last().Content.ToString()</p>
                    }
                }
                else
                {<p>ei leitud</p>}
                </td>
                <td>@if (item.Price != null)
                    {
                    <p>@item.Price</p>
                    }
                    else
                    {<p>ei leitud</p>}</td>
            </tr>
        }
    </table>
    <div>
        @if (Model.PageNumber > 1)
        {
            <span>@Ajax.ActionLink("Eelmine", "AjaxSearch", new RouteValueDictionary() { 
                                                                                       {"q", Model.Query}, 
                                                                                       {"p", (Model.PageNumber - 1).ToString()} },
                                                        new AjaxOptions
                                                        {
                                                            UpdateTargetId = "content",
                                                            HttpMethod = "GET",
                                                            InsertionMode = InsertionMode.Replace
                                                        })</span>
            //<span>@Html.ActionLink("Eelmine", "AjaxSearch", new RouteValueDictionary() { {"q", Model.Query}, {"p", (Model.PageNumber - 1).ToString()} })</span>
        }
        @if (Model.PageNumber < Model.NumPages)
        {
            <span>@Ajax.ActionLink("Järgmine", "AjaxSearch", new RouteValueDictionary() { 
                                                                                       {"q", Model.Query}, 
                                                                                       {"p", (Model.PageNumber + 1).ToString()} },
                                                        new AjaxOptions
                                                        {
                                                            UpdateTargetId = "content",
                                                            HttpMethod = "GET",
                                                            InsertionMode = InsertionMode.Replace
                                                        })</span>            
            //<span>@Html.ActionLink("Järgmine", "AjaxSearch", new RouteValueDictionary() { {"q", Model.Query}, {"p", (Model.PageNumber + 1).ToString()} })</span>
        }
    </div>
    }
    

</div>
